package com.itheima.global.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class JwtUtils {
    private static final String SECRET_KEY = "aXRoZWltYQ==";
    private static final long EXPIRATION_TIME = 12* 3600 * 1000;

    public static String generateJwt(Map<String, Object> dataMap) {
        return Jwts.builder()
               .signWith(SignatureAlgorithm.HS256, SECRET_KEY)
               .addClaims(dataMap)
               .setExpiration(new Date(System.currentTimeMillis() + EXPIRATION_TIME))
               .compact();
    }

    public static Claims parseJwt(String jwt) throws Exception{
        return Jwts.parser()
               .setSigningKey(SECRET_KEY)
               .parseClaimsJws(jwt)
               .getBody();
    }
}    